package main

import (
	"github.com/gin-gonic/gin"
	"tupu-go/controller/auth"
	neublaController "tupu-go/controller/nebula"
	"tupu-go/controller/node_edge"
	"tupu-go/controller/task"
	"tupu-go/middleware"
)

// 注册API路由
func RegisterAPIRoutes(r *gin.Engine) {
	// 创建控制器实例
	nodeTypeCtrl := node_edge.NewNodeTypeController()

	taskCtrl := task.NewTaskController()

	authCtrl := auth.NewAuthController()

	schemaCtrl := neublaController.NewSchemaController()

	publicGroup := r.Group("/api/v1") //无需认证的路由
	{
		publicGroup.POST("login", authCtrl.Login)
		schema := publicGroup.Group("/schema")
		{
			schema.POST("", schemaCtrl.CreateSchema)
			schema.POST("/generate-yaml", schemaCtrl.GenerateYAML)
		}
	}
	//========================================================================================================================
	authGroup := r.Group("/api/v1") //需要认证的路由
	authGroup.Use(middleware.AuthMiddleware())
	{
		// 节点类型管理
		nodeTypes := authGroup.Group("node")
		{
			nodeTypes.POST("", nodeTypeCtrl.CreateNodeType)
			nodeTypes.GET("", nodeTypeCtrl.ListNodeTypes)
			nodeTypes.GET("/:id", nodeTypeCtrl.GetNodeType)
			nodeTypes.PUT("/:id", nodeTypeCtrl.UpdateNodeType)
			nodeTypes.DELETE("/:id", nodeTypeCtrl.DeleteNodeType)
		}

		// 任务管理
		tasks := authGroup.Group("/tasks")
		{
			tasks.POST("", taskCtrl.CreateTask)
			tasks.GET("", taskCtrl.ListTasks)
			tasks.GET("/:task_id/node-types", taskCtrl.GetTaskNodeTypes)
			tasks.DELETE("/:task_id", taskCtrl.DeleteTask)
		}

	}
}
